package basic;

public class T2 {
	public static void main(String[] args) {
		int[] arr = { 1, 4, 2, 4, 3, 5, 1, 3, 6, 7, 10 };
		bubble_Sort(arr);
		select_sort(arr);
	}

	/*
	 * 冒泡排序后的顺序为从小到大
	 */
	public static void bubble_Sort(int[] arr) {
		int i, j, exchange;
		int len = arr.length;
		for (i = 0; i < len - 1; i++) {
			for (j = 0; j < len - i - 1; j++) {
				if (arr[j] > arr[j + 1]) {
					exchange = arr[j];
					arr[j] = arr[j + 1];
					arr[j + 1] = exchange;
				}
			}
		}
		for (int k : arr) {
			System.out.println(k);
		}
	}

	/**
	 * 直接排序
	 */
	public static void select_sort(int[] arr) {
		for (int i = 0; i < arr.length; i++) {
			int temp = arr[i];
			for (int j = i + 1; j < arr.length; j++) {
				if (arr[i] > arr[j]) {
					arr[j] = arr[i];
					arr[i] = temp;
					temp = arr[j];
				}
			}
		}
		for (int i : arr) {
			System.out.println(i);
		}
	}

}
